/**
 * @auth NoahLiu
 * @team 星城前端团队
 * 配合Uni完成自定义标题栏高度计算，以及通过 Pinia 全局共享
 */

import { defineStore } from "pinia";

export const useCustomNavigationStore = defineStore("customNavigation", {
  state: () => {
    return {
      /** 状态栏高度 */
      statusBar: 0,
      /** 自定义顶栏高度 */
      customBar: 0,
      rightPadding: 0,
    };
  },
  actions: {
    setState() {
      uni.getSystemInfo({
        success: (e) => {
          let statusBar = e.statusBarHeight as number;
          let custom;
          // #ifdef MP-WEIXIN
          custom = wx.getMenuButtonBoundingClientRect();
          // #endif
          // #ifndef MP-WEIXIN
          custom = { bottom: 32, top: 0, right: 0, width: 0 };
          // #endif
          let customBar = custom.bottom + custom.top - (e.statusBarHeight as number);
          let rightPadding = custom.width;
          this.statusBar = statusBar;
          this.customBar = customBar;
          this.rightPadding = rightPadding;
        },
      });
    },
  },
});
